home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / OutOfPhase1.01Source / OutOfPhase Folder / WaveTableSizeDialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-01  |  14.4 KB  |  470 lines  |  [TEXT/KAHL]

  1. /* WaveTableSizeDialog.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "WaveTableSizeDialog.h"
  31. #include "Screen.h"
  32. #include "EventLoop.h"
  33. #include "RadioButton.h"
  34. #include "SimpleButton.h"
  35. #include "WrapTextBox.h"
  36. #include "Memory.h"
  37. #include "Menus.h"
  38.  
  39.  
  40. #define XBORDER (13)
  41. #define YBORDER (13)
  42. #define BUTTONHEIGHT (12)
  43. #define SEPARATOR (5)
  44. #define BUTTONWIDTH (80)
  45.  
  46. #define MESSAGEX (XBORDER)
  47. #define MESSAGEY (YBORDER)
  48. #define MESSAGEHEIGHT (30)
  49.  
  50. #define BUTTON2X (MESSAGEX)
  51. #define BUTTON2Y (MESSAGEY + MESSAGEHEIGHT + (4 * SEPARATOR))
  52.  
  53. #define BUTTON4X (BUTTON2X)
  54. #define BUTTON4Y (BUTTON2Y + BUTTONHEIGHT + SEPARATOR)
  55.  
  56. #define BUTTON8X (BUTTON4X)
  57. #define BUTTON8Y (BUTTON4Y + BUTTONHEIGHT + SEPARATOR)
  58.  
  59. #define BUTTON16X (BUTTON8X)
  60. #define BUTTON16Y (BUTTON8Y + BUTTONHEIGHT + SEPARATOR)
  61.  
  62. #define BUTTON32X (BUTTON2X + BUTTONWIDTH)
  63. #define BUTTON32Y (BUTTON2Y)
  64.  
  65. #define BUTTON64X (BUTTON32X)
  66. #define BUTTON64Y (BUTTON32Y + BUTTONHEIGHT + SEPARATOR)
  67.  
  68. #define BUTTON128X (BUTTON64X)
  69. #define BUTTON128Y (BUTTON64Y + BUTTONHEIGHT + SEPARATOR)
  70.  
  71. #define BUTTON256X (BUTTON128X)
  72. #define BUTTON256Y (BUTTON128Y + BUTTONHEIGHT + SEPARATOR)
  73.  
  74. #define BUTTON512X (BUTTON32X + BUTTONWIDTH)
  75. #define BUTTON512Y (BUTTON32Y)
  76.  
  77. #define BUTTON1024X (BUTTON512X)
  78. #define BUTTON1024Y (BUTTON512Y + BUTTONHEIGHT + SEPARATOR)
  79.  
  80. #define BUTTON2048X (BUTTON1024X)
  81. #define BUTTON2048Y (BUTTON1024Y + BUTTONHEIGHT + SEPARATOR)
  82.  
  83. #define BUTTON4096X (BUTTON2048X)
  84. #define BUTTON4096Y (BUTTON2048Y + BUTTONHEIGHT + SEPARATOR)
  85.  
  86. #define BUTTON8192X (BUTTON512X + BUTTONWIDTH)
  87. #define BUTTON8192Y (BUTTON512Y)
  88.  
  89. #define BUTTON16384X (BUTTON8192X)
  90. #define BUTTON16384Y (BUTTON8192Y + BUTTONHEIGHT + SEPARATOR)
  91.  
  92. #define BUTTON32768X (BUTTON16384X)
  93. #define BUTTON32768Y (BUTTON16384Y + BUTTONHEIGHT + SEPARATOR)
  94.  
  95. #define BUTTON65536X (BUTTON32768X)
  96. #define BUTTON65536Y (BUTTON32768Y + BUTTONHEIGHT + SEPARATOR)
  97.  
  98. #define WINXSIZE (BUTTON65536X + BUTTONWIDTH + XBORDER)
  99.  
  100. #define MESSAGEWIDTH (WINXSIZE - (2 * XBORDER))
  101.  
  102. #define CANCELBUTTONX (XBORDER)
  103. #define CANCELBUTTONY (BUTTON65536Y + BUTTONHEIGHT + (5 * SEPARATOR))
  104. #define CANCELBUTTONWIDTH (80)
  105. #define CANCELBUTTONHEIGHT (21)
  106.  
  107. #define OKBUTTONY (CANCELBUTTONY)
  108. #define OKBUTTONWIDTH (CANCELBUTTONWIDTH)
  109. #define OKBUTTONHEIGHT (CANCELBUTTONHEIGHT)
  110. #define OKBUTTONX (WINXSIZE - XBORDER - OKBUTTONWIDTH)
  111.  
  112. #define WINYSIZE (OKBUTTONY + OKBUTTONHEIGHT + YBORDER)
  113.  
  114.  
  115. typedef struct
  116.     {
  117.         WinType*                        ScreenID;
  118.         RadioButtonRec*            Buttons[16];
  119.         SimpleButtonRec*        OKButton;
  120.         SimpleButtonRec*        CancelButton;
  121.     } WindowRec;
  122.  
  123.  
  124. /* redrawer for the thing */
  125. static void                    RedrawWaveDialog(WindowRec* Window)
  126.     {
  127.         long                            Scan;
  128.  
  129.         CheckPtrExistence(Window);
  130.         for (Scan = 0; Scan < 16; Scan += 1)
  131.             {
  132.                 RedrawRadioButton(Window->Buttons[Scan]);
  133.             }
  134.         RedrawSimpleButton(Window->OKButton);
  135.         RedrawSimpleButton(Window->CancelButton);
  136.         SetClipRect(Window->ScreenID,0,0,WINXSIZE,WINYSIZE);
  137.         DrawWrappedTextBox(Window->ScreenID,"Select the number of frames per wave table:",
  138.             GetUglyFont(),12,MESSAGEX,MESSAGEY,MESSAGEWIDTH,MESSAGEHEIGHT);
  139.     }
  140.  
  141.  
  142. /* ask for a new wave table size */
  143. long                                AskForNewWaveTableSize(long CurrentSize)
  144.     {
  145.         WindowRec*                Window;
  146.         MyBoolean                    LoopFlag;
  147.         long                            ReturnValue = CurrentSize;
  148.         long                            Scan;
  149.  
  150.         ERROR((CurrentSize != 2) && (CurrentSize != 4)
  151.             && (CurrentSize != 8) && (CurrentSize != 16) && (CurrentSize != 32)
  152.             && (CurrentSize != 64) && (CurrentSize != 128) && (CurrentSize != 256)
  153.             && (CurrentSize != 512) && (CurrentSize != 1024) && (CurrentSize != 2048)
  154.             && (CurrentSize != 4096) && (CurrentSize != 8192) && (CurrentSize != 16384)
  155.             && (CurrentSize != 32768) && (CurrentSize != 65536),PRERR(ForceAbort,
  156.             "AskForNewWaveTableSize:  bad input value"));
  157.         Window = (WindowRec*)AllocPtrCanFail(sizeof(WindowRec),"AskForNewWaveTableSize");
  158.         if (Window == NIL)
  159.             {
  160.              FailurePoint1:
  161.                 return CurrentSize;
  162.             }
  163.         Window->ScreenID = MakeNewWindow(eModelessDialogWindow,eWindowNotClosable,
  164.             eWindowNotZoomable,eWindowNotResizable,DialogLeftEdge(WINXSIZE),
  165.             DialogTopEdge(WINYSIZE),WINXSIZE,WINYSIZE,
  166.             (void (*)(void*))&RedrawWaveDialog,Window);
  167.         if (Window->ScreenID == NIL)
  168.             {
  169.              FailurePoint2:
  170.                 ReleasePtr((char*)Window);
  171.                 goto FailurePoint1;
  172.             }
  173.         SetWindowName(Window->ScreenID,"Wave Table Frames");
  174.         Window->Buttons[0] = NewRadioButton(Window->ScreenID,"2",BUTTON2X,BUTTON2Y,
  175.             BUTTONWIDTH,BUTTONHEIGHT);
  176.         if (Window->Buttons[0] == NIL)
  177.             {
  178.              FailurePoint3:
  179.                 KillWindow(Window->ScreenID);
  180.                 goto FailurePoint2;
  181.             }
  182.         Window->Buttons[1] = NewRadioButton(Window->ScreenID,"4",BUTTON4X,BUTTON4Y,
  183.             BUTTONWIDTH,BUTTONHEIGHT);
  184.         if (Window->Buttons[1] == NIL)
  185.             {
  186.              FailurePoint4:
  187.                 DisposeRadioButton(Window->Buttons[0]);
  188.                 goto FailurePoint3;
  189.             }
  190.         Window->Buttons[2] = NewRadioButton(Window->ScreenID,"8",BUTTON8X,BUTTON8Y,
  191.             BUTTONWIDTH,BUTTONHEIGHT);
  192.         if (Window->Buttons[2] == NIL)
  193.             {
  194.              FailurePoint5:
  195.                 DisposeRadioButton(Window->Buttons[1]);
  196.                 goto FailurePoint4;
  197.             }
  198.         Window->Buttons[3] = NewRadioButton(Window->ScreenID,"16",BUTTON16X,BUTTON16Y,
  199.             BUTTONWIDTH,BUTTONHEIGHT);
  200.         if (Window->Buttons[3] == NIL)
  201.             {
  202.              FailurePoint6:
  203.                 DisposeRadioButton(Window->Buttons[2]);
  204.                 goto FailurePoint5;
  205.             }
  206.         Window->Buttons[4] = NewRadioButton(Window->ScreenID,"32",BUTTON32X,BUTTON32Y,
  207.             BUTTONWIDTH,BUTTONHEIGHT);
  208.         if (Window->Buttons[4] == NIL)
  209.             {
  210.              FailurePoint7:
  211.                 DisposeRadioButton(Window->Buttons[3]);
  212.                 goto FailurePoint6;
  213.             }
  214.         Window->Buttons[5] = NewRadioButton(Window->ScreenID,"64",BUTTON64X,BUTTON64Y,
  215.             BUTTONWIDTH,BUTTONHEIGHT);
  216.         if (Window->Buttons[5] == NIL)
  217.             {
  218.              FailurePoint8:
  219.                 DisposeRadioButton(Window->Buttons[4]);
  220.                 goto FailurePoint7;
  221.             }
  222.         Window->Buttons[6] = NewRadioButton(Window->ScreenID,"128",BUTTON128X,
  223.             BUTTON128Y,BUTTONWIDTH,BUTTONHEIGHT);
  224.         if (Window->Buttons[6] == NIL)
  225.             {
  226.              FailurePoint9:
  227.                 DisposeRadioButton(Window->Buttons[5]);
  228.                 goto FailurePoint8;
  229.             }
  230.         Window->Buttons[7] = NewRadioButton(Window->ScreenID,"256",BUTTON256X,
  231.             BUTTON256Y,BUTTONWIDTH,BUTTONHEIGHT);
  232.         if (Window->Buttons[7] == NIL)
  233.             {
  234.              FailurePoint10:
  235.                 DisposeRadioButton(Window->Buttons[6]);
  236.                 goto FailurePoint9;
  237.             }
  238.         Window->Buttons[8] = NewRadioButton(Window->ScreenID,"512",BUTTON512X,
  239.             BUTTON512Y,BUTTONWIDTH,BUTTONHEIGHT);
  240.         if (Window->Buttons[8] == NIL)
  241.             {
  242.              FailurePoint11:
  243.                 DisposeRadioButton(Window->Buttons[7]);
  244.                 goto FailurePoint10;
  245.             }
  246.         Window->Buttons[9] = NewRadioButton(Window->ScreenID,"1024",BUTTON1024X,
  247.             BUTTON1024Y,BUTTONWIDTH,BUTTONHEIGHT);
  248.         if (Window->Buttons[9] == NIL)
  249.             {
  250.              FailurePoint12:
  251.                 DisposeRadioButton(Window->Buttons[8]);
  252.                 goto FailurePoint11;
  253.             }
  254.         Window->Buttons[10] = NewRadioButton(Window->ScreenID,"2048",BUTTON2048X,
  255.             BUTTON2048Y,BUTTONWIDTH,BUTTONHEIGHT);
  256.         if (Window->Buttons[10] == NIL)
  257.             {
  258.              FailurePoint13:
  259.                 DisposeRadioButton(Window->Buttons[9]);
  260.                 goto FailurePoint12;
  261.             }
  262.         Window->Buttons[11] = NewRadioButton(Window->ScreenID,"4096",BUTTON4096X,
  263.             BUTTON4096Y,BUTTONWIDTH,BUTTONHEIGHT);
  264.         if (Window->Buttons[11] == NIL)
  265.             {
  266.              FailurePoint14:
  267.                 DisposeRadioButton(Window->Buttons[10]);
  268.                 goto FailurePoint13;
  269.             }
  270.         Window->Buttons[12] = NewRadioButton(Window->ScreenID,"8192",BUTTON8192X,
  271.             BUTTON8192Y,BUTTONWIDTH,BUTTONHEIGHT);
  272.         if (Window->Buttons[12] == NIL)
  273.             {
  274.              FailurePoint15:
  275.                 DisposeRadioButton(Window->Buttons[11]);
  276.                 goto FailurePoint14;
  277.             }
  278.         Window->Buttons[13] = NewRadioButton(Window->ScreenID,"16384",BUTTON16384X,
  279.             BUTTON16384Y,BUTTONWIDTH,BUTTONHEIGHT);
  280.         if (Window->Buttons[13] == NIL)
  281.             {
  282.              FailurePoint16:
  283.                 DisposeRadioButton(Window->Buttons[12]);
  284.                 goto FailurePoint15;
  285.             }
  286.         Window->Buttons[14] = NewRadioButton(Window->ScreenID,"32768",BUTTON32768X,
  287.             BUTTON32768Y,BUTTONWIDTH,BUTTONHEIGHT);
  288.         if (Window->Buttons[14] == NIL)
  289.             {
  290.              FailurePoint17:
  291.                 DisposeRadioButton(Window->Buttons[13]);
  292.                 goto FailurePoint16;
  293.             }
  294.         Window->Buttons[15] = NewRadioButton(Window->ScreenID,"65536",BUTTON65536X,
  295.             BUTTON65536Y,BUTTONWIDTH,BUTTONHEIGHT);
  296.         if (Window->Buttons[15] == NIL)
  297.             {
  298.              FailurePoint18:
  299.                 DisposeRadioButton(Window->Buttons[14]);
  300.                 goto FailurePoint17;
  301.             }
  302.         Window->CancelButton = NewSimpleButton(Window->ScreenID,"Cancel",CANCELBUTTONX,
  303.             CANCELBUTTONY,CANCELBUTTONWIDTH,CANCELBUTTONHEIGHT);
  304.         if (Window->CancelButton == NIL)
  305.             {
  306.              FailurePoint19:
  307.                 DisposeRadioButton(Window->Buttons[15]);
  308.                 goto FailurePoint18;
  309.             }
  310.         Window->OKButton = NewSimpleButton(Window->ScreenID,"OK",OKBUTTONX,
  311.             OKBUTTONY,OKBUTTONWIDTH,OKBUTTONHEIGHT);
  312.         if (Window->OKButton == NIL)
  313.             {
  314.              FailurePoint20:
  315.                 DisposeSimpleButton(Window->CancelButton);
  316.                 goto FailurePoint19;
  317.             }
  318.         SetDefaultButtonState(Window->OKButton,True);
  319.  
  320.         /* set the button */
  321.         switch (CurrentSize)
  322.             {
  323.                 default:
  324.                     EXECUTE(PRERR(ForceAbort,"AskForNewWaveTableSize:  bad input value [2]"));
  325.                     break;
  326.                 case 2:
  327.                     SetRadioButtonState(Window->Buttons[0],True);
  328.                     break;
  329.                 case 4:
  330.                     SetRadioButtonState(Window->Buttons[1],True);
  331.                     break;
  332.                 case 8:
  333.                     SetRadioButtonState(Window->Buttons[2],True);
  334.                     break;
  335.                 case 16:
  336.                     SetRadioButtonState(Window->Buttons[3],True);
  337.                     break;
  338.                 case 32:
  339.                     SetRadioButtonState(Window->Buttons[4],True);
  340.                     break;
  341.                 case 64:
  342.                     SetRadioButtonState(Window->Buttons[5],True);
  343.                     break;
  344.                 case 128:
  345.                     SetRadioButtonState(Window->Buttons[6],True);
  346.                     break;
  347.                 case 256:
  348.                     SetRadioButtonState(Window->Buttons[7],True);
  349.                     break;
  350.                 case 512:
  351.                     SetRadioButtonState(Window->Buttons[8],True);
  352.                     break;
  353.                 case 1024:
  354.                     SetRadioButtonState(Window->Buttons[9],True);
  355.                     break;
  356.                 case 2048:
  357.                     SetRadioButtonState(Window->Buttons[10],True);
  358.                     break;
  359.                 case 4096:
  360.                     SetRadioButtonState(Window->Buttons[11],True);
  361.                     break;
  362.                 case 8192:
  363.                     SetRadioButtonState(Window->Buttons[12],True);
  364.                     break;
  365.                 case 16384:
  366.                     SetRadioButtonState(Window->Buttons[13],True);
  367.                     break;
  368.                 case 32768:
  369.                     SetRadioButtonState(Window->Buttons[14],True);
  370.                     break;
  371.                 case 65536:
  372.                     SetRadioButtonState(Window->Buttons[15],True);
  373.                     break;
  374.             }
  375.  
  376.         /* process user input */
  377.         LoopFlag = True;
  378.         while (LoopFlag)
  379.             {
  380.                 OrdType                        XLoc;
  381.                 OrdType                        YLoc;
  382.                 ModifierFlags            Modifiers;
  383.                 WinType*                    Crap;
  384.                 char                            KeyPress;
  385.                 MenuItemType*            MenuItem;
  386.                 EventType                    TheEvent;
  387.  
  388.                 TheEvent = GetAnEvent(&XLoc,&YLoc,&Modifiers,&Crap,&MenuItem,&KeyPress);
  389.                 switch (TheEvent)
  390.                     {
  391.                         default:
  392.                             break;
  393.                         case eCheckCursor:
  394.                             SetArrowCursor();
  395.                             break;
  396.                         case eNoEvent:
  397.                             break;
  398.                         case eKeyPressed:
  399.                             if (KeyPress == eCancelKey)
  400.                                 {
  401.                                     FlashButton(Window->CancelButton);
  402.                                     LoopFlag = False;
  403.                                     ReturnValue = CurrentSize;
  404.                                 }
  405.                             else if (KeyPress == 13)
  406.                                 {
  407.                                     FlashButton(Window->OKButton);
  408.                                     LoopFlag = False;
  409.                                 }
  410.                             break;
  411.                         case eMouseDown:
  412.                             for (Scan = 0; Scan < 16; Scan += 1)
  413.                                 {
  414.                                     if (RadioButtonHitTest(Window->Buttons[Scan],XLoc,YLoc))
  415.                                         {
  416.                                             if (RadioButtonMouseDown(Window->Buttons[Scan],XLoc,YLoc))
  417.                                                 {
  418.                                                     long                            Index;
  419.  
  420.                                                     for (Index = 0; Index < 16; Index += 1)
  421.                                                         {
  422.                                                             SetRadioButtonState(Window->Buttons[Index],False);
  423.                                                         }
  424.                                                     SetRadioButtonState(Window->Buttons[Scan],True);
  425.                                                     ReturnValue = (1L << (Scan + 1));
  426.                                                 }
  427.                                             goto JumpOutQuickPoint;
  428.                                         }
  429.                                 }
  430.                             if (SimpleButtonHitTest(Window->CancelButton,XLoc,YLoc))
  431.                                 {
  432.                                     if (SimpleButtonMouseDown(Window->CancelButton,XLoc,YLoc,NIL,NIL))
  433.                                         {
  434.                                             LoopFlag = False;
  435.                                             ReturnValue = CurrentSize;
  436.                                         }
  437.                                 }
  438.                             else if (SimpleButtonHitTest(Window->OKButton,XLoc,YLoc))
  439.                                 {
  440.                                     if (SimpleButtonMouseDown(Window->OKButton,XLoc,YLoc,NIL,NIL))
  441.                                         {
  442.                                             LoopFlag = False;
  443.                                         }
  444.                                 }
  445.                          JumpOutQuickPoint:
  446.                             break;
  447.                     }
  448.             }
  449.  
  450.         /* verify value */
  451.         ERROR((ReturnValue != 2) && (ReturnValue != 4)
  452.             && (ReturnValue != 8) && (ReturnValue != 16) && (ReturnValue != 32)
  453.             && (ReturnValue != 64) && (ReturnValue != 128) && (ReturnValue != 256)
  454.             && (ReturnValue != 512) && (ReturnValue != 1024) && (ReturnValue != 2048)
  455.             && (ReturnValue != 4096) && (ReturnValue != 8192) && (ReturnValue != 16384)
  456.             && (ReturnValue != 32768) && (ReturnValue != 65536),PRERR(ForceAbort,
  457.             "AskForNewWaveTableSize:  bad resulting value"));
  458.  
  459.         DisposeSimpleButton(Window->CancelButton);
  460.         DisposeSimpleButton(Window->OKButton);
  461.         for (Scan = 0; Scan < 16; Scan += 1)
  462.             {
  463.                 DisposeRadioButton(Window->Buttons[Scan]);
  464.             }
  465.         KillWindow(Window->ScreenID);
  466.         ReleasePtr((char*)Window);
  467.  
  468.         return ReturnValue;
  469.     }
  470.